<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/main.css">
    <link rel="stylesheet" href="../css/jquery-ui.css">
    <link href="../css/bootstrap.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="box" >
    <div class="box_border" style="border-bottom: none;">
        <div class="box_top"><b class="pl15">管理员管理</b></div>
        <div style="clear: both;"></div>
        <div class="mt10">
            <div id="table" class="mt10">
                <div class="box span9 oh" style="margin-left: auto; margin-right: auto">
                    <div class="fl mb5"><a class="ext_btn"  onclick="AddAdmin()" ><span class="add"></span>增加管理员</a></div>
                    <table id="approval_info1" width="100%" border="0" cellpadding="0" cellspacing="0" class="list_table" style="table-layout:fixed; font-size:1.2rem">
                        <tr>
                            <th class="td_center" >序号</th>
                            <th class="td_center" >账号</th>
                            <th class="td_center" >密码</th>
                            <th class="td_center" >可选操作</th>
                        </tr>
                        <tbody id="approval_info">
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="dialogAdmin" title="" style="display: none;">
    <form name="from1" >
        <div class="pb10 mb15 "> <div style="display: inline-block;width:46px;text-align: right;">账号:</div>
            <input type="text" name="admin_id" class="input-text lh30 ml " id="admin_id" size="30" onkeyup="value=value.replace(/[^\d]/g,'')" ><span style="color:red;font-size: 20px;">&nbsp;*</span></div>
        <div class="pb10"> <div style="display: inline-block;width:46px;text-align: right;"  >密码:</div>
            <input type="text" name="admin_pwd" class="input-text lh30 ml" id="admin_pwd" size="30"   ><span style="color:red;font-size: 20px;">&nbsp;*</span></div>
        <!--<div class="pb10 mb15"><div style="display: inline-block;width:100px;text-align: right;"  > 旺季时间:</div>-->
        <!--<input type="text" name="fire_time" class="input-text lh30 ml" size="30" id="card_number" ></div>-->
        <!--<input type="button" id="back" value="删除" class="ext_btn ext_btn_submit">-->
        <!--<input type="submit" id="save" value="保存" class="ext_btn ext_btn_submit">-->
    </form>
</div>
<div id="info" style="display: none;text-align:center;"></div>
</body>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui.js"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/config.js"></script>
<script>
    function adminCreateTable(){
        var phpUrl=url+"admin/Admin/AdminGetData.php";
        $.ajax({
            url:phpUrl,
            type:"POST",
            data:{model:"getAdminInfo"},
            async:true,
            success:function(data){
//                alert(data);
                var approve_info=$("#approval_info");
                data=JSON.parse(data);
                if(data.state==1){
                    var tableData=data.data;
                    approve_info.empty();
                    for(var i=0;i<tableData.length;i++)
                        approve_info.append(
                            '<tr><td class="td_center  " >' + (i+1) + '</td>' +
                            '<td class="td_center  " >' + tableData[i]['admin_ID'] + '</td>'+
                            '<td class="td_center  " >' + tableData[i]['admin_pwd'] + '</td>'+
                            '<td class="td_center"><a class="ext_btn modify" onclick="UpdateAdmin(this)"><span class="modify" ></span>编辑</a>'+
                            '<a class="ext_btn del" onclick="deleteAdmin('+tableData[i]['admin_id']+')"><span class="del" ></span>删除</a></td></tr>'
                    );
                }
            }
        });
    }
    function deleteAdmin(e){
//        alert(e);
        var phpUrl=url+"admin/Admin/AdminDeleteData.php";
        $.ajax({
            url:phpUrl,
            type:"POST",
            data:{admin_id:e},
            async:true,
            success:function(data){
//                alert(data);
                data=JSON.parse(data);
                if(data.state==1){
                    adminCreateTable();
                    dialogInfo("删除成功！");
                }
            }
        });
    }
    function UpdateAdmin(e){
        var phpUrl=url+"admin/Admin/AdminUpdateData.php";
        var thisTr= e.parentNode.parentNode;
        var admin_id=$("#admin_id");
        var admin_pwd=$("#admin_pwd");
        admin_id.attr('readonly','readonly');
        admin_id.addClass('disabled');
        admin_pwd.val(thisTr.childNodes[2].innerHTML);
        admin_id.val(thisTr.childNodes[1].innerHTML);
        $("#dialogAdmin").dialog({
            resizable: false,
            width:350,
            title: "管理员:"+thisTr.childNodes[1].innerHTML,
            modal: true,
            buttons: {
                '取消': function () {
                    $("#dialogAdmin").dialog("close");
                },
                '确定': function () {
                    $("#dialogAdmin").dialog("close");
                    var adminId=admin_id.val();
                    var adminPwd=admin_pwd.val();
                    $.ajax({
                        url:phpUrl,
                        type:"POST",
                        data:{model:"UpdateAdmin",admin_id:adminId,admin_pwd:adminPwd},
                        async:true,
                        success:function(data){
//                             alert(data);
                            data=JSON.parse(data);
                            if(data.state==1){
                                dialogInfo("保存成功！");
                                adminCreateTable();
                            }
                        }
                    });
                }
            }
        });
    }
    function AddAdmin(){
        var phpUrl=url+"admin/Admin/AdminAddData.php";
        var admin_id=$("#admin_id");
        var admin_pwd=$("#admin_pwd");
        admin_id.removeAttr('readonly');
        admin_id.val('');
        admin_pwd.val('');
        admin_id.removeClass('disabled');
        $("#dialogAdmin").dialog({
            resizable: false,
            width:350,
            title: "添加管理员",
            modal: true,
            buttons: {
                '取消': function () {
                    $("#dialogAdmin").dialog("close");
                },
                '确定': function () {
                    if(admin_id.val()!='') {
                        $("#dialogAdmin").dialog("close");
                        $.ajax({
                            url: phpUrl,
                            type: "POST",
                            data: {model: "addAdmin", admin_id: admin_id.val(), admin_pwd: admin_pwd.val()},
                            async: true,
                            success: function (data) {
//                alert(data);
                                data = JSON.parse(data);
                                if (data.state == 1) {
                                    dialogInfo("保存成功！");
                                    adminCreateTable();
                                } else {
                                    dialogInfo("添加失败管理员已存在！");
                                }
                            }
                        });
                    }else{
                        dialogInfo("账号不能为空！");
                    }
                }
            }
        });
    }
    function dialogInfo(e){
        $("#info").html(e).dialog({
            resizable: false,
            title: "信息",
            modal: true,
            buttons: {
                '确定': function () {
                    $("#info").dialog("close");
                }
            }
        });
        setTimeout('closeDialogInfo()',1000);
    }
    //关闭消息提示框
    function closeDialogInfo(){
        $("#info").dialog('close');
    }
    $(function () {
        adminCreateTable();
    })
</script>
</html>